package com.halobop.demo.admin.controller;


import com.halobop.demo.admin.dto.*;
import com.halobop.demo.admin.service.ISMSService;
import com.halobop.demo.common.CommonPage;
import com.halobop.demo.common.CommonResult;
import com.halobop.demo.mbg.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value = "短信相关模块")
@RestController
@RequestMapping("/api/admin/sms")
public class SMSController {

    @Autowired
    ISMSService smsService;

    @ApiOperation("发送验证码")
    @PostMapping("/sendcode")
    public CommonResult sendCode(@Valid SMSSendDto dto, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return CommonResult.validateFailed();
        }
        boolean ret = smsService.sendAuthCode(dto);
        if (ret){
            return CommonResult.success("验证码已发送");
        }else {
            return CommonResult.failed("验证码发送失败");
        }
    }

    @ApiOperation("验证验证码")
    @PostMapping("/verifyauthcode")
    public CommonResult verifyAuthCode(@Valid SMSVerifyDto dto, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return CommonResult.validateFailed();
        }
        boolean ret = smsService.verifyAuthCode(dto);
        if (!ret){
            return CommonResult.failed("验证码错误");
        }else {
            return CommonResult.success(null, "校验成功");
        }
    }

}
